package com.lsa.letcode.the86.partitionList;

import org.junit.Test;

import com.lsa.letcode.common.LetCodeTestBase;
import com.lsa.letcode.common.ListNode;

public class PartitionListTest extends LetCodeTestBase {
	@Test
	public void test() throws Exception {
		test(asList(), 3, asList());
		test(asList(4), 3, asList(4));
		test(asList(4), 5, asList(4));
		test(asList(4, 1), 3, asList(1, 4));
		test(asList(1, 4, 3, 2, 5, 2), 3, asList(1, 2, 2, 4, 3, 5));
		test(asList(1, 2, 3, 4, 5, 6), 6, asList(1, 2, 3, 4, 5, 6));
		
		test(asList(7, 7, 7, 7, 5, 5, 5, 8, 4), 6,
				asList(5, 5, 5, 4, 7, 7, 7, 7, 8));
		
		test(asList(6, 7, 7, 7, 7, 5, 5, 5, 8, 4, 6), 6,
				asList(5, 5, 5, 4, 6, 7, 7, 7, 7, 8, 6));

		test(asList(1, 7, 13, 17, 8), 12, asList(1, 7, 8, 13, 17));
		test(asList(1, 7, 13, 17, 8, 9), 12, asList(1, 7, 8, 9, 13, 17));
		test(asList(17, 8, 9, 1, 7, 13), 12, asList(8, 9, 1, 7, 17, 13));
		
		test(asList(1, 7, 8, 9, 13, 17), 12, asList(1, 7, 8, 9, 13, 17));

		test(asList(31, 22, 7, 44, 85, 91, 32, 17, 18, 9, 94), 50,
				asList(31, 22, 7, 44, 32, 17, 18, 9, 85, 91, 94));

	}

	private void test(ListNode linput, int partitionEl, ListNode expected) {
		Solution s = new Solution();
		ListNode actual = s.partition(linput, partitionEl);
		assertEqual(expected, actual);
	}
}